package com.qianyu.project.service.smj;

import com.qianyu.project.core.annotation.FlowBegin;
import com.qianyu.project.core.annotation.FlowEntry;
import com.qianyu.project.entity.LaborContract;
import com.qianyu.project.mapper.provider.smj.smjLaberControllerDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;

@Service
public class SmjLaberServiceImpl implements smjLaberService {

    @Autowired
    private smjLaberControllerDao ld;

    @Override//添加合同信息
    public String  Addlaber(String create_date,  String contract_name, String p_id, String contract_type, String contract_amount, String start_date, String end_date, String labor_org_id, String settle_type, String advance_pay, String deposit_amount, String payment_type, String contract_signatory, String pay_condition, String main_term, String comment, String attach_ids,String amount_upper) {
        String update_date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        String[] ids = update_date.split(" ");
        String ids1 =ids[0];
        String ids2 =ids[1];
        String[] ids3 = ids1.split("-");
        String[] ids4 = ids2.split(":");
        String id ="";
        for (int i = 0; i <ids3.length ; i++) {
            id += ids3[i];
        }
        for (int i = 0; i <ids4.length ; i++) {
            id += ids4[i];
        }
        ld.Addlaber( create_date, id, contract_name, p_id, contract_type, contract_amount, start_date, end_date, labor_org_id, settle_type, advance_pay, deposit_amount, payment_type, contract_signatory, pay_condition, main_term, comment, attach_ids,amount_upper);
        return id;
    }

    @Override//添加劳工工程量
    public void Addlaborworklist(String work_content, String unit, String work_count, String unit_price, String id) {
        Integer sum_price = Integer.valueOf(work_count)*Integer.valueOf(unit_price);
        ld.Addlaborworklist(work_content,unit,work_count,unit_price,sum_price,id);
    }


    @FlowBegin("labor_contract")//发起审批
    @Override
    public Integer FlowLaber(@FlowEntry("id") LaborContract laborContract) {
        ld.UpdateApproveStatus(1, laborContract.getId());
        return 1;
    }

    @Override//添加附件创建人
    public void UpdateInfo(String ids, String infoname) {
        if(!ObjectUtils.isEmpty(ids)){
            ld.UpdateInfo(ids,infoname);
        }
    }

    @Override//获取附件信息
    public List<Map<String ,Object>> getWorkList(String id) {
       return  ld.getWorkList(id);
    }

    @Override//获取审批内容
    public List<Map<String, Object>> getfromaudit(String id) {
        String fid = ld.getFid(id);
        return ld.getfromaudit(fid);
    }
}
